<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>

<script>
    function func(a, b) {
        return a + b;
    }

    function curring(fn, params) {
        let len = fn.length; // 获取函数的参数长度
        params = params || [];

        return function (...args) {
            let newArgs = params.concat(args);
            if (newArgs.length < len) {
                return curring.call(this, fn, newArgs);
            } else {
                return fn.apply(this, newArgs);
            }
        }
    }
    const curryFunc = curring(func);
    console.log(curryFunc(1)(2, 3));


    
    //实现一个add方法有如下效果add(1,2).add(3).add(4).ouput()，在output的时候输出前边数的和
    function add(...args) {
        return [...args]
    }
    Array.prototype.add = function (...args) {
        this.push(...args)
        return this
    }
    Array.prototype.output = function () {
        return this.reduce((a, b) => a + b, 0)
    }

    console.log(add(1, 2).add(3).add(4).output())



</script>
</html>